package com.gulimall.order.vo;

import lombok.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author kkk
 * @date 2022/8/3
 */
//订单页需要的数据
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class OrderConfirmVo {
    /**
     * 收货地址
     */
    @Getter
    @Setter
    private List<MemberAddressVo> address;

    /**
     * 所有选中的购物项
     */
    @Getter
    @Setter
    private List<OrderItemVo> items;

    /**
     * 优惠券信息
     */
    @Getter
    @Setter
    private Integer integration;

    /**
     * 订单总额
     */
    private BigDecimal total;
    /**
     * 应付金额
     */
    private BigDecimal payPrice;

    /**
     * 防重令牌
     */
    @Getter
    @Setter
    private String orderToken;

    public BigDecimal getTotal() {
        BigDecimal bigDecimal = new BigDecimal("0");
        if (items != null) {
            for (OrderItemVo item : items) {
                bigDecimal = bigDecimal.add(item.getPrice().multiply(new BigDecimal(item.getCount())));
            }
        }
        return bigDecimal;
    }

    public Integer getCount() {
        Integer count = 0;
        for (OrderItemVo item : items) {
            count += item.getCount();
        }
        return count;
    }
}
